package com.zzh.client.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zhengzihong
 * @version 1.0.0
 * @date 2018/12/13
 * @Description
 */
@RestController
public class HelloController {

    private Logger logger = LoggerFactory.getLogger(HelloController.class);


    @Value("${server.port}")
    private String serverPort;

    @Resource
    private DiscoveryClient discoveryClient;

    @RequestMapping(value = "/sayHello",method = RequestMethod.GET)
    public String sayHello() {

        ServiceInstance serviceInstance = discoveryClient.getLocalServiceInstance();

        logger.info("/hello,host:{},service_id:{}", serviceInstance.getHost(), serviceInstance.getServiceId());
        return "hello world ---"+serverPort;


    }
}
